// components/popup/payment/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    currentDate:{
      type:Date,
      value: new Date().getTime(),
    },
    deliveryDate:{
      type:String,
      value:''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    currentDate: new Date().getTime(),
    minDate: new Date().getTime(),
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      } else if (type === 'month') {
        return `${value}月`;
      }
      return value;
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 关闭
    onClose () {
      this.triggerEvent('close')
    },
    confirm(event) {
      this.setData({
        currentDate: event.detail,
        show: false,
      });
      let date = new Date(this.data.currentDate);
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      let m = "-";
      let d = "-";
      if (month < 10) {
        m = "-0"
      }
      if (day < 10) {
        d = "-0"
      }
      this.setData({
        deliveryDate: year + m + month + d + day
      });
      this.triggerEvent('confirm', year + m + month + d + day)
    },
    cancel(event) {
      this.setData({
        show: false,
      });
    },
  }
});
